package com.supermap.dataservice.cloud.disastercloud;

import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.cloud.disastercloud.DisasterCloudService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author aqua
 * @description
 * @date 2018年11月16 下午 6:03
 * @email 1301584033@qq.com
 */
@Service
public class DisasterCloudServiceImpl implements DisasterCloudService {

    @Resource
    private DisasterCloudMapper disasterCloudMapper;


    @Override
    public JSONUtil inertDiststerCollerct(String userId, String disasterId) {
        int count= disasterCloudMapper.inertDiststerCollerct(userId,disasterId);
        if(count>0){
            return  new JSONUtil();
        }
        return new JSONUtil().setCode(100).setIsSuccess(false).setMsg("收藏失败");
    }

    @Override
    public JSONUtil delDiststerCollerct(String userId, String disasterId) {
        int count= disasterCloudMapper.delDiststerCollerct(userId,disasterId);
        if(count>0){
            return  new JSONUtil();
        }
        return new JSONUtil().setCode(100).setIsSuccess(false).setMsg("取消收藏失败");
    }

    @Override
    public JSONUtil getPageDisasterList(String areaCode, String userId, String farmId, Integer pageNum, Integer pageSise, Integer type,Integer lev,String beginTime,String endTime) {
        JSONUtil jsonUtil=new JSONUtil();
        List<DiststerList> listList=null;
        pageNum=(pageNum-1)*pageSise;
        String ak=null;
        try {
            if(type==1){
                //所有列表
                listList=disasterCloudMapper.getPageDisasterList(areaCode,userId,farmId,pageNum,pageSise,null,lev,beginTime,endTime);
            }
            if(type==2){
                ak="1";
                //我的列表
                listList=disasterCloudMapper.getPageDisasterList(areaCode,userId,farmId,pageNum,pageSise,"1",lev,beginTime,endTime);
            }
            if(type==3){
                ak="2";
                //我的收藏的列表
                listList=disasterCloudMapper.getPageDisasterList(areaCode,userId,farmId,pageNum,pageSise,"2",lev,beginTime,endTime);
            }
            for (DiststerList diststerList:listList){
                diststerList.setMapList(disasterCloudMapper.getPageDisasterContent(diststerList.getDisaterId(),0,3));
            }

        }catch (Exception e){
            System.out.println("错错错"+e.getMessage());
          return   jsonUtil.setMsg("查询失败").setIsSuccess(false).setCode(100);

        }

        return jsonUtil.setData(listList).setCountSum(disasterCloudMapper.getPageDisasterListCount(areaCode,userId,farmId,ak,lev,beginTime,endTime));
    }

    @Override
    public JSONUtil getPageDisasterContent(String disasterId, Integer pageNum, Integer pageSise) {
        JSONUtil jsonUtil=new JSONUtil();
        pageNum=(pageNum-1)*pageSise;
        try {
            jsonUtil.setData(disasterCloudMapper.getPageDisasterContent(disasterId,pageNum,pageSise));
        }catch (Exception e){
            System.out.println(e.getMessage()+"错错错错");
            return   jsonUtil.setMsg("查询失败").setIsSuccess(false).setCode(100);
        }
        return jsonUtil;
    }


}
